package countLargestGroup;

import java.util.HashMap;

public class Solution {

    public int countLargestGroup(int n) {
        int[] arr=new int[n];
        int max=0;
        for (int i = 1; i <=n ; i++) {
            int sum=get(i);
            arr[sum]++;
            if(arr[sum]>max){
                max=arr[sum];
            }
        }
        int res=0;
        for (int i = 0; i < n; i++) {
            if(arr[i]==max){
                res++;
            }
        }
        return res;
    }
    private int get(int n){
        int sum=0;
        while(n>0){
            sum+=n%10;
            n/=10;
        }
        return sum;
    }
}